```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>算法解析：打家劫舍问题</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .code-block {
            background-color: #1e293b;
            border-left: 4px solid #7c3aed;
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(124, 58, 237, 0.2);
            z-index: -1;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="min-h-screen">
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <div class="flex justify-center mb-6">
                <div class="bg-white bg-opacity-20 p-3 rounded-full">
                    <i class="fas fa-lock-open text-2xl"></i>
                </div>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">打家劫舍问题</h1>
            <p class="text-xl opacity-90 max-w-2xl mx-auto mb-8">动态规划思想的经典应用案例解析</p>
            <div class="flex justify-center space-x-4">
                <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">#动态规划</div>
                <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">#算法优化</div>
                <div class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">#LeetCode</div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-4xl mx-auto px-6 py-12">
        <!-- Problem Description -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-10 w-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">问题描述</h2>
            </div>
            <div class="bg-white rounded-xl p-8 shadow-lg card-hover">
                <p class="text-lg leading-relaxed mb-6">你是一个专业的小偷，计划沿着一条街偷窃房屋。每间房内都藏有一定的现金，<span class="highlight font-medium">相邻的房屋装有相互连通的防盗系统</span>，如果两间相邻的房屋在同一晚上被小偷闯入，系统会自动报警。</p>
                <p class="text-lg leading-relaxed mb-6">给定一个代表每个房屋存放金额的非负整数数组，计算你不触动警报装置的情况下，一夜之内能够偷窃到的最高金额。</p>
                <div class="bg-yellow-50 border-l-4 border-yellow-400 p-4 mb-6">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-yellow-400"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-yellow-700"><strong>示例</strong>: 输入 <code class="bg-gray-100 px-2 py-1 rounded">[1,2,3,1]</code>，输出 <code class="bg-gray-100 px-2 py-1 rounded">4</code>（偷窃第 1 间和第 3 间房屋）</p>
                        </div>
                    </div>
                </div>
                <div class="flex items-center text-purple-600">
                    <i class="fas fa-bolt mr-2"></i>
                    <span class="font-medium">核心考点:</span>
                    <span class="ml-2 bg-purple-100 px-3 py-1 rounded-full text-sm">动态规划</span>
                </div>
            </div>
        </section>

        <!-- Solution Approach -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-10 w-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">解题思路</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl p-8 shadow-lg card-hover">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-2 rounded-full mr-4">
                            <i class="fas fa-brain text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-bold">动态规划解析</h3>
                    </div>
                    <p class="text-gray-700 mb-4">定义 <code class="bg-gray-100 px-2 py-1 rounded">dp[i]</code> 为偷到第 <code class="bg-gray-100 px-2 py-1 rounded">i</code> 个房子时的最大收益，则状态转移方程为：</p>
                    <div class="bg-gray-100 p-4 rounded-lg mb-4">
                        <p class="font-mono text-lg text-center font-bold">dp[i] = max(dp[i-1], dp[i-2] + nums[i])</p>
                    </div>
                    <p class="text-gray-700 mb-4">对于每个房屋，我们有两个选择：</p>
                    <ul class="list-disc pl-5 space-y-2 mb-4">
                        <li>不偷当前房屋：最大收益等于前一个房屋的最大收益</li>
                        <li>偷当前房屋：最大收益等于前两个房屋的最大收益加上当前房屋的金额</li>
                    </ul>
                    <div class="text-sm text-gray-500">
                        <p><i class="fas fa-clock mr-1"></i> 时间复杂度: O(n)</p>
                        <p><i class="fas fa-memory mr-1"></i> 空间复杂度: O(n) 或优化为 O(1)</p>
                    </div>
                </div>
                <div>
                    <div class="mermaid">
                        graph TD
                            A[开始] --> B{是否空数组?}
                            B -->|是| C[返回0]
                            B -->|否| D{数组长度=1?}
                            D -->|是| E[返回nums[0]]
                            D -->|否| F[初始化dp数组]
                            F --> G[dp[0]=nums[0], dp[1]=max(nums[0],nums[1])]
                            G --> H[循环i从2到n-1]
                            H --> I[dp[i]=max(dp[i-1], dp[i-2]+nums[i])]
                            I --> J[返回dp[n-1]]
                    </div>
                </div>
            </div>
        </section>

        <!-- Code Implementation -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="h-10 w-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">代码实现</h2>
            </div>
            <div class="bg-white rounded-xl overflow-hidden shadow-lg card-hover">
                <div class="bg-gray-800 px-4 py-3 flex items-center">
                    <div class="flex space-x-2 mr-4">
                        <div class="w-3 h-3 rounded-full bg-red-500"></div>
                        <div class="w-3 h-3 rounded-full bg-yellow-500"></div>
                        <div class="w-3 h-3 rounded-full bg-green-500"></div>
                    </div>
                    <div class="text-white text-sm">Solution.java</div>
                </div>
                <div class="code-block p-6 text-gray-100 overflow-x-auto">
                    <pre><code class="language-java">
public int rob(int[] nums) {
    // 处理边界情况
    if (nums == null || nums.length == 0) {
        return 0;
    }
    if (nums.length == 1) {
        return nums[0];
    }
    
    // 创建动态规划数组，dp[i]表示偷到第i个房子时的最大收益
    int[] dp = new int[nums.length];
    
    // 初始化基本情况
    dp[0] = nums[0];  // 只有一个房子时，最大收益就是偷这个房子
    dp[1] = Math.max(nums[0], nums[1]);  // 有两个房子时，选择收益较大的那个偷
    
    // 从第3个房子开始计算最大收益
    for (int i = 2; i < nums.length; i++) {
        // 对于当前房子，有两种选择：
        // 1. 不偷当前房子，最大收益等于偷到前一个房子的最大收益
        // 2. 偷当前房子，最大收益等于偷到前两个房子的最大收益加上当前房子的金额
        dp[i] = Math.max(dp[i-1], dp[i-2] + nums[i]);
    }
    
    // 返回偷到最后一个房子时的最大收益
    return dp[nums.length - 1];
}
                    </code></pre>
                </div>
            </div>
        </section>

        <!-- Optimization -->
        <section>
            <div class="flex items-center mb-6">
                <div class="h-10 w-1 bg-purple-600 mr-4"></div>
                <h2 class="text-3xl font-bold font-serif">空间优化</h2>
            </div>
            <div class="bg-white rounded-xl p-8 shadow-lg card-hover">
                <div class="flex items-center mb-4">
                    <div class="bg-purple-100 p-2 rounded-full mr-4">
                        <i class="fas fa-rocket text-purple-600"></i>
                    </div>
                    <h3 class="text-xl font-bold">从O(n)到O(1)的空间优化</h3>
                </div>
                <p class="text-gray-700 mb-4">观察状态转移方程，我们发现 <code class="bg-gray-100 px-2 py-1 rounded">dp[i]</code> 只依赖于 <code class="bg-gray-100 px-2 py-1 rounded">dp[i-1]</code> 和 <code class="bg-gray-100 px-2 py-1 rounded">dp[i-2]</code>，因此可以用两个变量代替整个数组：</p>
                <div class="code-block p-6 text-gray-100 overflow-x-auto mt-4">
                    <pre><code class="language-java">
public int rob(int[] nums) {
    if (nums == null || nums.length == 0) return 0;
    if (nums.length == 1) return nums[0];
    
    int prev2 = nums[0];
    int prev1 = Math.max(nums[0], nums[1]);
    
    for (int i = 2; i < nums.length; i++) {
        int current = Math.max(prev1, prev2 + nums[i]);
        prev2 = prev1;
        prev1 = current;
    }
    
    return prev1;
}
                    </code></pre>
                </div>
                <div class="mt-6 p-4 bg-blue-50 rounded-lg border-l-4 border-blue-400">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-info-circle text-blue-400"></i>
                        </div>
                        <div class="ml-3">
                            <p class="text-blue-700"><strong>优化效果</strong>: 空间复杂度从 O(n) 降低到 O(1)，减少了内存使用，同时保持了相同的 O(n) 时间复杂度。</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```